
package com.jf.cloud.order.controller.platform;

import cn.hutool.core.date.DateUtil;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.order.service.OrderStatisticsService;
import com.jf.cloud.order.vo.OrderOverviewVO;
import com.jf.cloud.order.vo.OrderRefundStatisticsVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.Operation;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zz
 * @Date 2021/4/30 14:01
 */
@RestController("platformOrderStatisticsController")
@RequestMapping("/p/order_statistics")
@Tag(name = "platform-订单数据统计接口")
public class OrderStatisticsController {

    @Autowired
    private OrderStatisticsService orderStatisticsService;

    @GetMapping("/get_detail_by_hour")
    @Operation(summary = "获取当天与昨天订单实时统计数据" , description = "获取当天与昨天订单实时统计数据")
    public ServerResponseEntity<OrderOverviewVO> getDetailInfoByHour() {
        OrderOverviewVO orderOverviewVO = orderStatisticsService.getDetailInfoByHour(null);
        return ServerResponseEntity.success(orderOverviewVO);
    }

    @GetMapping("/get_order_info_by_day_count")
    @Operation(summary = "获取近多少天内的订单统计数据" , description = "获取近多少天内订单内的订单统计数据")
    @Parameters({
            @Parameter(name = "dayCount", description = "天数（几天内的统计数据）", required = false)
    })
    public ServerResponseEntity<OrderOverviewVO> getCurrentMonthInfoByDay(@ParameterObject @RequestParam(value = "dayCount", defaultValue = "30") Integer dayCount) {
        OrderOverviewVO orderOverviewVO = orderStatisticsService.getOrderInfoByDayCountAndShopId(null, dayCount);
        return ServerResponseEntity.success(orderOverviewVO);
    }

    @GetMapping("/list_spu_ranking_by_order_count")
    @Operation(summary = "获取商品订单数量排行榜" , description = "获取商品订单数量排行榜")
    @Parameters({
            @Parameter(name = "dayCount", description = "天数（几天内的排行榜）"),
            @Parameter(name = "limit", description = "排行榜条数")
    })
    public ServerResponseEntity<List<OrderOverviewVO>> listSpuRankingByPayActual(@ParameterObject @RequestParam(value = "dayCount", defaultValue = "30") Integer dayCount,
                                                                                 @ParameterObject @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
        List<OrderOverviewVO> orderOverviewVOList = orderStatisticsService.listSpuRankingByOrderCount(null, DateUtil.endOfDay(DateUtil.date()), dayCount, limit);
        return ServerResponseEntity.success(orderOverviewVOList);
    }

    @GetMapping("/list_shop_ranking_by_pay_actual")
    @Operation(summary = "获取店铺销售排行榜" , description = "获取店铺销售排行榜")
    @Parameters({
            @Parameter(name = "dayCount", description = "天数（几天内的排行榜）"),
            @Parameter(name = "limit", description = "排行榜条数")
    })
    public ServerResponseEntity<List<OrderOverviewVO>> listShopRankingByPayActual(@ParameterObject @RequestParam(value = "dayCount", defaultValue = "30") Integer dayCount,
                                                                                  @ParameterObject @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
        List<OrderOverviewVO> orderOverviewVOList = orderStatisticsService.listShopRankingByPayActual(DateUtil.endOfDay(DateUtil.date()), dayCount, limit);
        return ServerResponseEntity.success(orderOverviewVOList);
    }

    @GetMapping("/list_shop_ranking_by_refund_count")
    @Operation(summary = "获取店铺退款订单数量排行榜" , description = "获取店铺退款订单数量排行榜")
    @Parameters({
            @Parameter(name = "dayCount", description = "天数（几天内的排行榜）"),
            @Parameter(name = "limit", description = "排行榜条数")
    })
    public ServerResponseEntity<List<OrderRefundStatisticsVO>> listRefundRankingByProd(@ParameterObject @RequestParam(value = "dayCount", defaultValue = "30") Integer dayCount,
                                                                                       @ParameterObject @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
        List<OrderRefundStatisticsVO> orderRefundStatisticsVOList = orderStatisticsService.listShopRankingByRefundCount(DateUtil.endOfDay(DateUtil.date()), dayCount, limit);
        return ServerResponseEntity.success(orderRefundStatisticsVOList);
    }

}
